﻿using System;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenCube.Nbt
{
	/// <summary>
	/// Deserializes NBT data from streams
	/// </summary>
	[ContractClass(typeof(NbtDeserializerContracts))]
	public interface INbtDeserializer
	{
		/// <summary>
		/// Deserialize given stream as a <see cref="INbtDictionary"/>.
		/// </summary>
		/// <param name="stream">The stream to deserialize from.</param>
		/// <returns>The dictionary holding the deserialized data.</returns>
		INbtDictionary Deserialize(Stream stream);
	}

	[ContractClassFor(typeof(INbtDeserializer))]
	abstract class NbtDeserializerContracts
		: INbtDeserializer
	{
		public INbtDictionary Deserialize(Stream stream)
		{
			Contract.Requires<ArgumentNullException>(stream != null, "A stream is required");
			Contract.Requires<InvalidOperationException>(stream.CanRead, "The stream must be readable");
			Contract.Ensures(Contract.Result<INbtDictionary>() != null);
			throw new NotImplementedException();
		}
	}
}
